<template>
	<view style="padding-bottom:300rpx;">
		<page-head :title="'验车详情'" :headtype="2"></page-head>
		<view class="available marginAuto" v-if="orderstatus == 1">待支付<text style="margin-left:20rpx;color:#666666;font-size:24rpx;">验车订单已核验，请您尽快完成支付~</text></view>
		<view class="available marginAuto" v-if="orderstatus == 2">待验车</view>
		<view class="available marginAuto" v-if="orderstatus == 3">已完成</view>
		<view class="coach flex marginAuto" v-if="datas.coach_user_id > 0">
			<view class="coachimg">
				<image :src="apifun.URLimg+datas.coach_avatar" mode=""></image>
			</view>
			<view class="coachmsg">
				<view class="coachmsgname flex">
					<view class="coachmsgname-n">{{ datas.coach_username }}</view>
					<view class="coachmsgname-rz">认证教练</view>
				</view> 
				<view class="coachmsgage">
					<text style="margin-right:40rpx;">年龄：{{ datas.coach_age }}岁</text>
					<text>驾龄：{{ datas.coach_drive_year }}年</text>
				</view>
				<view class="coachmsgcar mainColor">{{ datas.brand }}</view>
				<view class="coachmsgcars flex">
					<view class="flex">
						<text class="mainColor" style="margin-right:10rpx;">o</text>
						<text>车型：{{ datas.shape_name[0] }}</text>
					</view>
					<view class="flex">
						<text class="mainColor" style="margin-right:10rpx;">o</text>
						<text>车况：{{ datas.condition_name }}</text>
					</view>
				</view>
				<view class="coachmsgcars flex">
					<view class="flex">
						<text class="mainColor" style="margin-right:10rpx;">o</text>
						<text>类型：{{ datas.type_name }}</text>
					</view>
					<view class="flex">
						<text class="mainColor" style="margin-right:10rpx;">o</text>
						<text>价格：{{ datas.amount }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="available marginAuto">联系信息</view>
		<view class="listmsg marginAuto">
			<view class="itemmsg flex marginAuto">
				<view class="itemmsgtitle">姓名：</view>
				<view class="itemmsgr">{{ datas.name }}</view>
			</view>
			<view class="itemmsg flex marginAuto">
				<view class="itemmsgtitle">电话：</view>
				<view class="itemmsgr">{{ datas.mobile }}</view>
			</view>
			<view class="itemmsg flex marginAuto" v-if="datas.complete_time">
				<view class="itemmsgtitle">验车时间：</view>
				<view class="itemmsgr">{{ datas.complete_time }}</view>
			</view>
			<view class="itemmsg flex marginAuto" style="padding-bottom:0rpx;">
				<view class="itemmsgtitle" style="line-height:60rpx;">验车地址：</view>
				<view class="itemmsgr" style="width:70%;">
					<view class="itemmsgr-qy ellipsis01" style="text-align:right;">{{ datas.address }}</view>
					<!-- <view class="itemmsgr-site ellipsis01" style="text-align:right;font-size: 24rpx;color:#666666;">南三环汽车城1号楼1023凯迪拉克4S店</view> -->
				</view>
			</view>
		</view>
		<view class="available marginAuto">下单信息</view>
		<view class="listmsg marginAuto">
			<view class="itemmsg flex marginAuto">
				<view class="itemmsgtitle">订单号：</view>
				<view class="itemmsgr">{{ datas.order_sn }}</view>
			</view>
			<view class="itemmsg flex marginAuto" v-if="datas.orderstatus > 1">
				<view class="itemmsgtitle">支付方式：</view>
				<view class="itemmsgr" v-if="datas.pay_type == 1">微信支付</view>
				<!-- <view class="itemmsgr" v-if="datas.pay_type == 2">先验后付</view> -->
			</view>
			<view class="itemmsg flex marginAuto">
				<view class="itemmsgtitle">支付金额：</view>
				<view class="itemmsgr">￥{{ datas.amount }}</view>
			</view>
			<view class="itemmsg flex marginAuto">
				<view class="itemmsgtitle">下单时间</view>
				<view class="itemmsgr">{{ datas.create_time }}</view>
			</view>
		</view>
		<view class="bottombtn flex">
			<view v-if="orderstatus == 1" class="testbtneach mainBg baiColor" style="width: 100%;" @click="iscarpay=true">支付</view>
			<block v-if="orderstatus == 2">
				<view class="testbtneach mainColor" style="width:30%;background:#D8F0FF;" @click="$refs.closetest.open()">取消</view>
				<view class="testbtneach baiColor mainBg flex" style="width:66%;">
					<view class="marginAuto">
						<image style="width:32rpx;height:32rpx;display: inline-block;position: relative;top:7rpx;" :src="apifun.serveimg+'qrcode.png'" mode=""></image>
						<!-- <text class="marginAuto" style="margin-left: 10rpx;" @click="qrcodefun()">出示签到码</text> -->
					</view>
				</view>
			</block>
			<view v-if="orderstatus == 3" class="testbtneach" style="width: 100%;background:#FFEEEE;color:#FC2A2A;">已完成</view>
			<view v-if="orderstatus == 4" class="testbtneach" style="width: 100%;background:#F0F0F0;color:#999999;">已取消</view>
		</view>
		<view class="complain" @click="apifun.navigate('/pages/my/validateplain','id='+datas.id)">投诉</view>
		<!-- 弹窗 -->
		<uv-popup ref="closetest" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">确定要取消</view>
				<view class="closetestdoc">本次验车吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.closetest.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="closeenter">确定</view>
				</view>
			</view>
		</uv-popup>
		<!-- 提交 -->
		<view class="bottompopup">
			<view class="zg" v-if="iscarpay" @click="iscarpay = false"></view>
			<view class="pup" :class="iscarpay ? 'showtop':''" style="width:100%;">
				<view class="pupclose" @click="iscarpay = false">
					<uv-icon name="close" size="22" color="#222222"></uv-icon>
				</view>
				<view class="paypup">
					<view class="money"><text style="font-size: 20rpx;">￥</text>{{ datas.amount }}</view>
					<view class="paytype">
						<view class="paytypetitle marginAuto">支付方式</view>
						<view class="paytypemain marginAuto">
							<view class="paytypeeach marginAuto flex" @click="paytype = 1">
								<view class="paytypeetitle">微信支付<text style="color: #9E9E9E;margin-left:16rpx;">剩余5元可抵扣</text></view>
								<view class="paytypeer">
									<uv-icon name="checkmark-circle-fill" size="22" :color="paytype == 1 ? '#1686F8':'#E5E5E5'"></uv-icon>
								</view>
							</view>
							<!-- <view class="paytypeeach marginAuto flex" @click="paytype = 2">
								<view class="paytypeetitle">先验后付<text style="color: #9E9E9E;margin-left:16rpx;">0元下单，验车完成之后支付</text></view>
								<view class="paytypeer">
									<uv-icon name="checkmark-circle-fill" size="22" :color="paytype == 2 ? '#1686F8':'#E5E5E5'"></uv-icon>
								</view>
							</view> -->
							<view class="paytypeeach marginAuto flex" @click="apifun.navigate('/pages/home/discount','ordersn='+datas.order_sn+'&apisite=/api/verifyCart/getVerifyCartOrderCouponList')">
								<view class="paytypeetitle">优惠券</view>
								<view class="paytypeer flex">
									<view class="rtxt" style="color:#999999;" v-if="!disitem.id">请选择</view>
									<view class="rtxt" style="color:#333;" v-if="disitem.id">￥{{ disitem.amount }}</view>
									<uv-icon name="arrow-right" size="16" color="#999999"></uv-icon>
								</view> 
							</view>
						</view>
					</view>
				</view>
				<view class="marginAuto" style="width:600rpx;margin:60rpx auto;">
					<uv-button text="立即支付" @click="enterpay()" :customStyle="{
						'background':'#1686F8',
						'color':'#ffffff',
						'font-size':'30rpx',
						'width':'600rpx',
						'height':'100rpx',
						'border-radius':'100rpx'
					}"></uv-button>
				</view>
			</view>
		</view>
		<!-- <uv-popup ref="paypup" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">支付</view>
				<view class="closetestdoc">确认支付此订单吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.paypup.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="payenter">确定</view>
				</view>
			</view>
		</uv-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				id:'',
				orderstatus:'', // 1待支付 2待验车 3已完成4已取消
				datas:{},
				paytype:1,
				iscarpay:false,
				disitem:{}
			};
		},
		onLoad(option) {
			this.id = option.id
			this.initData();
			uni.$on('emitdiscount',(data)=>{  // 优惠券
				this.disitem = data.disitem;
			});
		},
		methods: {
			initData(){
				let sendData = {
					order_id:this.id
				};
				this.apifun.unirequest('/api/verifyCart/getOrderDetail','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas = datas;
						this.orderstatus = datas.pay_status
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			qrcodefun(item,index){
				uni.setStorageSync('qrcode',this.datas.qrcode_url);
				setTimeout(()=>{
					this.apifun.navigate('/pages/my/mytestqrcode')
				},300)
			},
			closeenter(){  // 取消试驾
				let sendData = {
					order_id:this.acitem.id
				};
				this.apifun.unirequest('/api/verifyCart/cancelOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.$refs.closetest.close();
						this.orderstatus = 4;
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			enterpay(){  // 确认支付
				let sendData = {
					order_sn:this.datas.order_sn,
					user_coupon_id:this.disitem.id || '',
					pay_type:this.paytype
				};
				this.apifun.unirequest('/api/verifyCart/payVerifyCartOrder','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.apifun.wxpaymini(datas,()=>{
							this.apifun.navigate('/pages/home/paysuccess')
						})
					}else{
						this.apifun.toast(res.msg)
					}
				})
			}
		},
	};
</script>

<style scoped lang="scss">
	@import '@/public/alert.scss';
	@import '../../public/popupb.scss';
	page{
		background: #F7F7F7;
	}
	.available{
		width: 690rpx;
		padding: 30rpx 0 0;
		line-height:50rpx;
		color:#222222;
		font-size: 32rpx;
		font-weight: 600;
	}
	.coach{
		width: 650rpx;
		padding: 20rpx;
		border-radius: 20rpx;
		margin-top: 20rpx;
		background: linear-gradient(to top,#ffffff,#DCEDFF);
		.coachimg{
			width: 150rpx;
			height: 220rpx;
			image{
				width: 150rpx;
				height: 220rpx;
				border-radius: 10rpx;
			}
		}
		.coachmsg{
			width: 70%;
			margin-left: 15rpx;
			.coachmsgname{
				.coachmsgname-n{
					color: #222222;
					font-size: 30rpx;
					font-weight: 600;
					margin-right:28rpx;
					line-height: 50rpx;
				}
				.coachmsgname-rz{
					display: inline-block;
					height:50rpx;
					line-height: 50rpx;
					color:#FF720C;
					font-size:24rpx;
					padding: 0 10rpx;
					background: #FFF1E2;
					border-radius:4rpx;
				}
			}
			.coachmsgage{
				font-size: 24rpx;
				color: #666666;
				padding: 10rpx 0;
			}
			.coachmsgcar{
				display: inline-block;
				height:50rpx;
				line-height: 50rpx;
				font-size:24rpx;
				padding: 0 12rpx;
				background:#E7F2FF;
				border-radius:4rpx;
			}
			.coachmsgcars{
				justify-content: space-between;
				flex-wrap: wrap;
				color: #333333;
				font-size: 26rpx;
				line-height:40rpx;
			}
		}
	}
	.listmsg{
		width:630rpx;
		padding: 30rpx;
		border-radius: 20rpx;
		background: #fff;
		margin-top: 20rpx;
		.itemmsg{
			padding-bottom:50rpx;
			line-height: 50rpx;
			justify-content: space-between;
			.itemmsgtitle{
				color: #333333;
				font-size: 28rpx;
			}
			.itemmsgr{
				color: #333333;
				font-size: 30rpx;
			}
		}
	}
	.bottombtn{
		position:fixed;
		bottom:100rpx;
		padding:30rpx 5%;
		width:90%;
		height: 100rpx;
		background: #fff;
		justify-content: space-between;
		.testbtneach{
			border-radius: 100rpx;
			line-height: 100rpx;
			height: 100rpx;
			text-align: center;
			font-size:30rpx;
		}
	}
	.complain{
		position:fixed;
		bottom:0;
		width: 100%;
		height:100rpx;
		line-height:100rpx;
		text-align: center;
		background: #fff;
		color: #D0D0D0;
		font-size: 30rpx;
	}
	// --支付方式
	.paypup{
		.money{
			padding: 80rpx 0 40rpx;
			color: #222222;
			font-size: 60rpx;
			text-align: center;
		}
		.paytype{
			.paytypetitle{
				width: 690rpx;
				font-size: 28rpx;
				color: #222222;
			}
			.paytypemain{
				.paytypeeach{
					width: 630rpx;
					margin-top: 20rpx;
					padding: 20rpx 30rpx;
					background:#F6F6F6;
					border-radius: 20rpx;
					justify-content: space-between;
					.paytypeetitle{
						color: #222222;
						font-size: 30rpx;
						line-height: 50rpx;
					}
					.paytypeer{
						.rtxt{
							font-size:30rpx;
						}
					}
				}
			}
		}
	}
</style>